package com.dcy.daily.service.service.impl;

import com.dcy.daily.common.core.base.BaseService;
import com.dcy.daily.core.model.Book;
import com.dcy.daily.service.service.DemoService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @author duanchunyu
 * @version 1.0.0
 * @createTime 2021年07月02日 14:11:00
 */
@Service
public class DemoServiceImpl extends BaseService implements DemoService {

    @Override
    @Cacheable(cacheNames = "book",keyGenerator = "keyGenerator")
    public Book getByIsbn(String isbn,String title) {
        simulateSlowService();
        return new Book(isbn, title);
    }


    private void simulateSlowService() {
        try {
            long time = 3000L;
            Thread.sleep(time);
        } catch (InterruptedException e) {
            throw new IllegalStateException(e);
        }
    }
}
